/******************************************************************************
//             INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//    Copyright(c) 2000 - 2001 Intel Corporation. All Rights Reserved.
//
//  VSS: 
//     $Workfile: $
//     $Revision: $
//     $Date:     $
//     $Archive:  $
//
//  Description:
//      Intel(R) Integrated Performance Primitives - JPEG Helper file.
//      This file contains "YCbCr to BGRA" conversion functions for decoding.
//
//  History:
//     Date        Author         Changes
//     2008/12/21  Jerry Hu       Modified (Version 0.2, MCU processing)
//
********************************************************************************/
#include "_ippjpeg.h"

/*
// The following routines implement the color conversion equations
// from CCIR Recommendation 601.
//
// In floating point notation, YCbCr->BGR:
//    R = (Y+128)            + 1.40200*(Cr)
//    G = (Y+128) - (0.34414*(Cb)) - (0.71414*(Cr))
//    B = (Y+128) + (1.77200*(Cb)
//
// In fixed point notation (using 10 bits), YCbCr->BGR: 
// (Y, Cb, Cr are level shifted by -128)
//
//    R = Y + 128 + (1436*Cr)/1024
//      = Y + ((1436*Cr + 131584) >> 10)
//
//    G = Y + 128 - ((352*Cb + 731*Cr)/1024)
//      = Y - ((352*Cb + 731*Cr - 131584) >> 10)
//
//    B = Y + 128 + ((1815*Cb)/1024)
//      = Y + ((1815*Cb + 131584) >> 10)
//
//
//    Note that a rounding technique for the right-shift operation is
//    incorporated directly into these fixed point equations
//    (i.e., a right-shift of N is preceded by adding 2^(N-1)).
//    Here the P in the macro name means a "partial" equation
//
*/


/* YCbCr->BGR */
#define _LS_YCC2BGR_PR(Cr)\
    (((1436 * (Cr)) + 131584) >> 10)

#define _LS_YCC2BGR_PG(Cb, Cr)\
   (((352 * (Cb)) + (731 * (Cr)) - 131584) >> 10)

#define _LS_YCC2BGR_PB(Cb)\
   (((1815 * (Cb)) + 131584) >> 10)

/******************************************************************************
// Name:             ippiYCbCr444ToBGRALS_MCU_16s8u_P3C3
// Description:      Converts MCU from YCbCr444 to BGRA. The size is 8x8
// Input Arguments: 
//       pSrcMCU[3]: Identifies three pointer array. 
//                   pSrcMCU[0] point to Y  block.
//                   pSrcMCU[1] point to Cb block.
//                   pSrcMCU[2] point to Cr block.
//          dstStep: Specifies the number of bytes in a line of the source image. 
//
// Output Arguments:
//          pDstBGRA: Identifies output image data buffer. It was sorted block by bock.
//                  
// Remarks:      
//                   1. The start address of each "pSrcMCU[]" shall be aligned at 4byte boundary.
//                   2. It is better to do this alignement at 32byte boundary to optimize 
//                      D-Cache accessing.
//                   
// Returns:         
//    IPP_STATUS_OK: Succeeds.
//
******************************************************************************/
IPPFUN(IppStatus, ippiYCbCr444ToBGRALS_MCU_16s8u_P3C3)  (const Ipp16s *pSrcMCU[3],
                                                               Ipp8u  *pDstBGRA, 
							                                   int    dstStep)
{
    int j;
    Ipp16s y;
    int yr[8], yg[8], yb[8];
    const Ipp16s *pSrcMCUY, *pSrcMCUCb, *pSrcMCUCr;

    _IPP_CHECK_ARG(NULL!=pSrcMCU);
    _IPP_CHECK_ARG((NULL!=pSrcMCU[0])  && (NULL!=pSrcMCU[1])  && (NULL!=pSrcMCU[2]));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrcMCU[0]));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrcMCU[1]));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrcMCU[2]));
    _IPP_CHECK_ARG(NULL!=pDstBGRA);
    _IPP_CHECK_ARG((32<=dstStep) || (-32>=dstStep));
    
    pSrcMCUY =pSrcMCU[0];
    pSrcMCUCb=pSrcMCU[1];
    pSrcMCUCr=pSrcMCU[2];

    for (j=8; j>0; j--) {

		/* Calculate partial R, G, B for pixel 0 */
        yr[0] = _LS_YCC2BGR_PR(pSrcMCUCr[0]);
        yg[0] = _LS_YCC2BGR_PG(pSrcMCUCb[0], pSrcMCUCr[0]);
        yb[0] = _LS_YCC2BGR_PB(pSrcMCUCb[0]);

		/* Calculate partial R, G, B for pixel 1 */
        yr[1] = _LS_YCC2BGR_PR(pSrcMCUCr[1]);
        yg[1] = _LS_YCC2BGR_PG(pSrcMCUCb[1], pSrcMCUCr[1]);
        yb[1] = _LS_YCC2BGR_PB(pSrcMCUCb[1]);

		/* Calculate partial R, G, B for pixel 2 */
        yr[2] = _LS_YCC2BGR_PR(pSrcMCUCr[2]);
        yg[2] = _LS_YCC2BGR_PG(pSrcMCUCb[2], pSrcMCUCr[2]);
        yb[2] = _LS_YCC2BGR_PB(pSrcMCUCb[2]);

		/* Calculate partial R, G, B for pixel 3 */
        yr[3] = _LS_YCC2BGR_PR(pSrcMCUCr[3]);
        yg[3] = _LS_YCC2BGR_PG(pSrcMCUCb[3], pSrcMCUCr[3]);
        yb[3] = _LS_YCC2BGR_PB(pSrcMCUCb[3]);

		/* Calculate partial R, G, B for pixel 4 */
        yr[4] = _LS_YCC2BGR_PR(pSrcMCUCr[4]);
        yg[4] = _LS_YCC2BGR_PG(pSrcMCUCb[4], pSrcMCUCr[4]);
        yb[4] = _LS_YCC2BGR_PB(pSrcMCUCb[4]);

		/* Calculate partial R, G, B for pixel 5 */
        yr[5] = _LS_YCC2BGR_PR(pSrcMCUCr[5]);
        yg[5] = _LS_YCC2BGR_PG(pSrcMCUCb[5], pSrcMCUCr[5]);
        yb[5] = _LS_YCC2BGR_PB(pSrcMCUCb[5]);

		/* Calculate partial R, G, B for pixel 6 */
        yr[6] = _LS_YCC2BGR_PR(pSrcMCUCr[6]);
        yg[6] = _LS_YCC2BGR_PG(pSrcMCUCb[6], pSrcMCUCr[6]);
        yb[6] = _LS_YCC2BGR_PB(pSrcMCUCb[6]);

		/* Calculate partial R, G, B for pixel 7 */
        yr[7] = _LS_YCC2BGR_PR(pSrcMCUCr[7]);
        yg[7] = _LS_YCC2BGR_PG(pSrcMCUCb[7], pSrcMCUCr[7]);
        yb[7] = _LS_YCC2BGR_PB(pSrcMCUCb[7]);

		/* Calculate BGR data of pixel 0 and write to destination */
        y = pSrcMCUY[0];
        pDstBGRA[ 0]  = _IPP_CLIP_8U(y + yb[0]);
        pDstBGRA[ 1]  = _IPP_CLIP_8U(y - yg[0]);
        pDstBGRA[ 2]  = _IPP_CLIP_8U(y + yr[0]);
        //pDstBGRA[3]  = Alpha

		/* Calculate BGR data of pixel 1 and write to destination */
        y = pSrcMCUY[1];
        pDstBGRA[ 4] = _IPP_CLIP_8U(y + yb[1]);
        pDstBGRA[ 5] = _IPP_CLIP_8U(y - yg[1]);
        pDstBGRA[ 6] = _IPP_CLIP_8U(y + yr[1]);
        //pDstBGRA[7]  = Alpha

		/* Calculate BGR data of pixel 2 and write to destination */
        y = pSrcMCUY[2];
        pDstBGRA[ 8] = _IPP_CLIP_8U(y + yb[2]);
        pDstBGRA[ 9] = _IPP_CLIP_8U(y - yg[2]);
        pDstBGRA[10] = _IPP_CLIP_8U(y + yr[2]);
        //pDstBGRA[11]  = Alpha

		/* Calculate BGR data of pixel 3 and write to destination */
        y = pSrcMCUY[3];
        pDstBGRA[12] = _IPP_CLIP_8U(y + yb[3]);
        pDstBGRA[13] = _IPP_CLIP_8U(y - yg[3]);
        pDstBGRA[14] = _IPP_CLIP_8U(y + yr[3]);
        //pDstBGRA[15]  = Alpha

		/* Calculate BGR data of pixel 4 and write to destination */
        y = pSrcMCUY[4];
        pDstBGRA[16] = _IPP_CLIP_8U(y + yb[4]);
        pDstBGRA[17] = _IPP_CLIP_8U(y - yg[4]);
        pDstBGRA[18] = _IPP_CLIP_8U(y + yr[4]);
        //pDstBGRA[19]  = Alpha

		/* Calculate BGR data of pixel 5 and write to destination */
        y = pSrcMCUY[5];
        pDstBGRA[20] = _IPP_CLIP_8U(y + yb[5]);
        pDstBGRA[21] = _IPP_CLIP_8U(y - yg[5]);
        pDstBGRA[22] = _IPP_CLIP_8U(y + yr[5]);
        //pDstBGRA[23]  = Alpha

		/* Calculate BGR data of pixel 6 and write to destination */
        y = pSrcMCUY[6];
        pDstBGRA[24] = _IPP_CLIP_8U(y + yb[6]);
        pDstBGRA[25] = _IPP_CLIP_8U(y - yg[6]);
        pDstBGRA[26] = _IPP_CLIP_8U(y + yr[6]);
        //pDstBGRA[27]  = Alpha

		/* Calculate BGR data of pixel 7 and write to destination */
        y = pSrcMCUY[7];
        pDstBGRA[28] = _IPP_CLIP_8U(y + yb[7]);
        pDstBGRA[29] = _IPP_CLIP_8U(y - yg[7]);
        pDstBGRA[30] = _IPP_CLIP_8U(y + yr[7]);
        //pDstBGRA[31]  = Alpha

		/* Update the pointers to input Y, Cb, Cr for next row */
        pSrcMCUY  += 8;
        pSrcMCUCb += 8;
        pSrcMCUCr += 8;

		/* Update the pointer to output BGR data for next row */
        pDstBGRA += dstStep;

    } /* for (j=8; j>0; j--) */

    return IPP_STATUS_OK;
}


/******************************************************************************
// Name:             ippiYCbCr422ToBGRALS_MCU_16s8u_P3C3
// Description:      Converts MCU from YCbCr422 to BGRA. The size is 16x8
// Input Arguments: 
//       pSrcMCU[3]: Identifies three pointer array. 
//                   pSrcMCU[0] point to Y  block.
//                   pSrcMCU[1] point to Cb block.
//                   pSrcMCU[2] point to Cr block.
//          dstStep: Specifies the number of bytes in a line of the source image. 
//
// Output Arguments:
//          pDstBGRA: Identifies output image data buffer. It was sorted block by bock.
//                  
// Remarks:      
//                   1. The start address of "pDst" shall be aligned at 4byte boundary.
//                   2. It is better to do this alignement at 32byte boundary to optimize 
//                      D-Cache accessing.
//                   
// Returns:         
//    IPP_STATUS_OK: Succeeds.
//
******************************************************************************/
IPPFUN(IppStatus, ippiYCbCr422ToBGRALS_MCU_16s8u_P3C3) (const Ipp16s *pSrcMCU[3],
                                                              Ipp8u  *pDstBGRA, 
							                                  int    dstStep) 
{
    int i, j;
    Ipp16s y;
    int nOffset;
    int yr[4], yg[4], yb[4];
    const Ipp16s *pSrcMCUY, *pSrcMCUCb, *pSrcMCUCr;

    _IPP_CHECK_ARG(NULL!=pSrcMCU);
    _IPP_CHECK_ARG((NULL!=pSrcMCU[0])  && (NULL!=pSrcMCU[1])  && (NULL!=pSrcMCU[2]));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrcMCU[0]));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrcMCU[1]));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrcMCU[2]));
    _IPP_CHECK_ARG(NULL!=pDstBGRA);
    _IPP_CHECK_ARG((32<=dstStep) || (-32>=dstStep));
    
    pSrcMCUY =pSrcMCU[0];
    pSrcMCUCb=pSrcMCU[1];
    pSrcMCUCr=pSrcMCU[2];

    nOffset = 8*dstStep-32;

    for (i=2; i>0; i--) {

        for(j=8; j>0; j--) {

		    /* Calculate partial R, G, B for pixel group 0 (pixels 0-1) */
            yr[0] = _LS_YCC2BGR_PR(pSrcMCUCr[0]);
            yg[0] = _LS_YCC2BGR_PG(pSrcMCUCb[0], pSrcMCUCr[0]);
            yb[0] = _LS_YCC2BGR_PB(pSrcMCUCb[0]);

		    /* Calculate partial R, G, B for pixel group 1 (pixels 2-3) */
            yr[1] = _LS_YCC2BGR_PR(pSrcMCUCr[1]);
            yg[1] = _LS_YCC2BGR_PG(pSrcMCUCb[1], pSrcMCUCr[1]);
            yb[1] = _LS_YCC2BGR_PB(pSrcMCUCb[1]);

		    /* Calculate partial R, G, B for pixel group 2 (pixels 4-5) */
            yr[2] = _LS_YCC2BGR_PR(pSrcMCUCr[2]);
            yg[2] = _LS_YCC2BGR_PG(pSrcMCUCb[2], pSrcMCUCr[2]);
            yb[2] = _LS_YCC2BGR_PB(pSrcMCUCb[2]);

		    /* Calculate partial R, G, B for pixel group 3 (pixels 6-7) */
            yr[3] = _LS_YCC2BGR_PR(pSrcMCUCr[3]);
            yg[3] = _LS_YCC2BGR_PG(pSrcMCUCb[3], pSrcMCUCr[3]);
            yb[3] = _LS_YCC2BGR_PB(pSrcMCUCb[3]);

		    /* Update the pointers to input Cb and Cr to the next row */
            pSrcMCUCb += 8;
            pSrcMCUCr += 8;

		    /* Calculate BGR data of pixel 0 and write to destination */
            y = pSrcMCUY[0];
            pDstBGRA[ 0] = _IPP_CLIP_8U(y + yb[0]);
            pDstBGRA[ 1] = _IPP_CLIP_8U(y - yg[0]);
            pDstBGRA[ 2] = _IPP_CLIP_8U(y + yr[0]);
            //pDstBGRA[3]  = Alpha

		    /* Calculate BGR data of pixel 1 and write to destination */
            y = pSrcMCUY[1];
            pDstBGRA[ 4] = _IPP_CLIP_8U(y + yb[0]);
            pDstBGRA[ 5] = _IPP_CLIP_8U(y - yg[0]);
            pDstBGRA[ 6] = _IPP_CLIP_8U(y + yr[0]);
            //pDstBGRA[7]  = Alpha

		    /* Calculate BGR data of pixel 2 and write to destination */
            y = pSrcMCUY[2];
            pDstBGRA[ 8] = _IPP_CLIP_8U(y + yb[1]);
            pDstBGRA[ 9] = _IPP_CLIP_8U(y - yg[1]);
            pDstBGRA[10] = _IPP_CLIP_8U(y + yr[1]);
            //pDstBGRA[11]  = Alpha

		    /* Calculate BGR data of pixel 3 and write to destination */
            y = pSrcMCUY[3];
            pDstBGRA[12] = _IPP_CLIP_8U(y + yb[1]);
            pDstBGRA[13] = _IPP_CLIP_8U(y - yg[1]);
            pDstBGRA[14] = _IPP_CLIP_8U(y + yr[1]);
            //pDstBGRA[5]  = Alpha

		    /* Calculate BGR data of pixel 4 and write to destination */
            y = pSrcMCUY[4];
            pDstBGRA[16] = _IPP_CLIP_8U(y + yb[2]);
            pDstBGRA[17] = _IPP_CLIP_8U(y - yg[2]);
            pDstBGRA[18] = _IPP_CLIP_8U(y + yr[2]);
            //pDstBGRA[19]  = Alpha

		    /* Calculate BGR data of pixel 5 and write to destination */
            y = pSrcMCUY[5];
            pDstBGRA[20] = _IPP_CLIP_8U(y + yb[2]);
            pDstBGRA[21] = _IPP_CLIP_8U(y - yg[2]);
            pDstBGRA[22] = _IPP_CLIP_8U(y + yr[2]);
            //pDstBGRA[23]  = Alpha

		    /* Calculate BGR data of pixel 6 and write to destination */
            y = pSrcMCUY[6];
            pDstBGRA[24] = _IPP_CLIP_8U(y + yb[3]);
            pDstBGRA[25] = _IPP_CLIP_8U(y - yg[3]);
            pDstBGRA[26] = _IPP_CLIP_8U(y + yr[3]);
            //pDstBGRA[27]  = Alpha

		    /* Calculate BGR data of pixel 7 and write to destination */
            y = pSrcMCUY[7];
            pDstBGRA[28] = _IPP_CLIP_8U(y + yb[3]);
            pDstBGRA[29] = _IPP_CLIP_8U(y - yg[3]);
            pDstBGRA[30] = _IPP_CLIP_8U(y + yr[3]);
            //pDstBGRA[31]  = Alpha

		    /* Update the pointer to output BGR data for the next row */
            pDstBGRA += dstStep;

		    /* Update the pointer to input Y of the next row */
            pSrcMCUY      += 8;

        } /* for(j=8; j>0; j--) */

        pDstBGRA-=(nOffset);
        pSrcMCUCb -= 60;
        pSrcMCUCr -= 60;
    }

    return IPP_STATUS_OK;
}

/******************************************************************************
// Name:             ippiYCbCr411ToBGRALS_MCU_16s8u_P3C3
// Description:      Converts MCU from YCbCr411 to BGRA. The size is 16x16
// Input Arguments: 
//       pSrcMCU[3]: Identifies three pointer array. 
//                   pSrcMCU[0] point to Y  block.
//                   pSrcMCU[1] point to Cb block.
//                   pSrcMCU[2] point to Cr block.
//          dstStep: Specifies the number of bytes in a line of the source image. 
//
// Output Arguments:
//          pDstBGRA: Identifies output image data buffer. It was sorted block by bock.
//                  
// Remarks:      
//                   1. The start address of "pDst" shall be aligned at 4byte boundary.
//                   2. It is better to do this alignement at 32byte boundary to optimize 
//                      D-Cache accessing.
//                   
// Returns:         
//    IPP_STATUS_OK: Succeeds.
//
******************************************************************************/
IPPFUN(IppStatus, ippiYCbCr411ToBGRALS_MCU_16s8u_P3C3)(const Ipp16s *pSrcMCU[3],
                                                             Ipp8u  *pDstBGRA, 
							                                 int    dstStep)
{
    int i, j;
    int nOffset;
    Ipp16s y;
    int yr[4], yg[4], yb[4];
    const Ipp16s *pSrcMCUY, *pSrcMCUCb, *pSrcMCUCr;

    _IPP_CHECK_ARG(NULL!=pSrcMCU);
    _IPP_CHECK_ARG((NULL!=pSrcMCU[0])  && (NULL!=pSrcMCU[1])  && (NULL!=pSrcMCU[2]));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrcMCU[0]));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrcMCU[1]));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrcMCU[2]));
    _IPP_CHECK_ARG(NULL!=pDstBGRA);
    _IPP_CHECK_ARG((32<=dstStep) || (-32>=dstStep));
    
    pSrcMCUY =pSrcMCU[0];
    pSrcMCUCb=pSrcMCU[1];
    pSrcMCUCr=pSrcMCU[2];

    nOffset = 8*dstStep-32;

    for (i=4; i>0; i--){

        /* Two rows (start from the even row) are processed in every loop */
        for (j=8; j>0; j-=2) {

            /* Calculate patial R, G, B for pixel group 0 */
            yr[0] = _LS_YCC2BGR_PR(pSrcMCUCr[0]);
            yg[0] = _LS_YCC2BGR_PG(pSrcMCUCb[0], pSrcMCUCr[0]);
            yb[0] = _LS_YCC2BGR_PB(pSrcMCUCb[0]);

            /* Calculate patial R, G, B for pixel group 1 */
            yr[1] = _LS_YCC2BGR_PR(pSrcMCUCr[1]);
            yg[1] = _LS_YCC2BGR_PG(pSrcMCUCb[1], pSrcMCUCr[1]);
            yb[1] = _LS_YCC2BGR_PB(pSrcMCUCb[1]);

            /* Calculate patial R, G, B for pixel group 2 */
            yr[2] = _LS_YCC2BGR_PR(pSrcMCUCr[2]);
            yg[2] = _LS_YCC2BGR_PG(pSrcMCUCb[2], pSrcMCUCr[2]);
            yb[2] = _LS_YCC2BGR_PB(pSrcMCUCb[2]);

            /* Calculate patial R, G, B for pixel group 3 */
            yr[3] = _LS_YCC2BGR_PR(pSrcMCUCr[3]);
            yg[3] = _LS_YCC2BGR_PG(pSrcMCUCb[3], pSrcMCUCr[3]);
            yb[3] = _LS_YCC2BGR_PB(pSrcMCUCb[3]);

		    /* Update the pointers to the input Cb and Cr for the next loop */
            pSrcMCUCb += 8;
            pSrcMCUCr += 8;

		    /* Calculate BGR data of the even row and write to destination */

		    /* pixel 0 */
            y = pSrcMCUY[0];
            pDstBGRA[ 0] = _IPP_CLIP_8U(y + yb[0]);
            pDstBGRA[ 1] = _IPP_CLIP_8U(y - yg[0]);
            pDstBGRA[ 2] = _IPP_CLIP_8U(y + yr[0]);
            //pDstBGRA[3]  = Alpha

		    /* pixel 1 */
            y = pSrcMCUY[1];
            pDstBGRA[ 4] = _IPP_CLIP_8U(y + yb[0]);
            pDstBGRA[ 5] = _IPP_CLIP_8U(y - yg[0]);
            pDstBGRA[ 6] = _IPP_CLIP_8U(y + yr[0]);
            //pDstBGRA[7]  = Alpha

		    /* pixel 2 */
            y = pSrcMCUY[2];
            pDstBGRA[ 8] = _IPP_CLIP_8U(y + yb[1]);
            pDstBGRA[ 9] = _IPP_CLIP_8U(y - yg[1]);
            pDstBGRA[10] = _IPP_CLIP_8U(y + yr[1]);
            //pDstBGRA[11]  = Alpha

		    /* pixel 3 */
            y = pSrcMCUY[3];
            pDstBGRA[12] = _IPP_CLIP_8U(y + yb[1]);
            pDstBGRA[13] = _IPP_CLIP_8U(y - yg[1]);
            pDstBGRA[14] = _IPP_CLIP_8U(y + yr[1]);
            //pDstBGRA[15]  = Alpha

		    /* pixel 4 */
            y = pSrcMCUY[4];
            pDstBGRA[16] = _IPP_CLIP_8U(y + yb[2]);
            pDstBGRA[17] = _IPP_CLIP_8U(y - yg[2]);
            pDstBGRA[18] = _IPP_CLIP_8U(y + yr[2]);
            //pDstBGRA[19]  = Alpha

		    /* pixel 5 */
            y = pSrcMCUY[5];
            pDstBGRA[20] = _IPP_CLIP_8U(y + yb[2]);
            pDstBGRA[21] = _IPP_CLIP_8U(y - yg[2]);
            pDstBGRA[22] = _IPP_CLIP_8U(y + yr[2]);
            //pDstBGRA[23]  = Alpha

		    /* pixel 6 */
            y = pSrcMCUY[6];
            pDstBGRA[24] = _IPP_CLIP_8U(y + yb[3]);
            pDstBGRA[25] = _IPP_CLIP_8U(y - yg[3]);
            pDstBGRA[26] = _IPP_CLIP_8U(y + yr[3]);
            //pDstBGRA[27]  = Alpha

		    /* pixel 7 */
            y = pSrcMCUY[7];
            pDstBGRA[28] = _IPP_CLIP_8U(y + yb[3]);
            pDstBGRA[29] = _IPP_CLIP_8U(y - yg[3]);
            pDstBGRA[30] = _IPP_CLIP_8U(y + yr[3]);
            //pDstBGRA[31]  = Alpha

            /* Update the pointer to the output BGR data for the next row */
            pDstBGRA += dstStep;
		    /* Update the pointer to the input Y for the next row */
            pSrcMCUY += 8;

		    /* Calculate BGR data of the odd row and write to destination */

		    /* Pixel 0 */
            y = pSrcMCUY[0];
            pDstBGRA[ 0] = _IPP_CLIP_8U(y + yb[0]);
            pDstBGRA[ 1] = _IPP_CLIP_8U(y - yg[0]);
            pDstBGRA[ 2] = _IPP_CLIP_8U(y + yr[0]);
            //pDstBGRA[3]  = Alpha

		    /* Pixel 1 */
            y = pSrcMCUY[1];
            pDstBGRA[ 4] = _IPP_CLIP_8U(y + yb[0]);
            pDstBGRA[ 5] = _IPP_CLIP_8U(y - yg[0]);
            pDstBGRA[ 6] = _IPP_CLIP_8U(y + yr[0]);
            //pDstBGRA[7]  = Alpha

		    /* Pixel 2 */
            y = pSrcMCUY[2];
            pDstBGRA[ 8] = _IPP_CLIP_8U(y + yb[1]);
            pDstBGRA[ 9] = _IPP_CLIP_8U(y - yg[1]);
            pDstBGRA[10] = _IPP_CLIP_8U(y + yr[1]);
            //pDstBGRA[11]  = Alpha

		    /* Pixel 3 */
            y = pSrcMCUY[3];
            pDstBGRA[12] = _IPP_CLIP_8U(y + yb[1]);
            pDstBGRA[13] = _IPP_CLIP_8U(y - yg[1]);
            pDstBGRA[14] = _IPP_CLIP_8U(y + yr[1]);
            //pDstBGRA[15]  = Alpha

		    /* Pixel 4 */
            y = pSrcMCUY[4];
            pDstBGRA[16] = _IPP_CLIP_8U(y + yb[2]);
            pDstBGRA[17] = _IPP_CLIP_8U(y - yg[2]);
            pDstBGRA[18] = _IPP_CLIP_8U(y + yr[2]);
            //pDstBGRA[19]  = Alpha

		    /* Pixel 5 */
            y = pSrcMCUY[5];
            pDstBGRA[20] = _IPP_CLIP_8U(y + yb[2]);
            pDstBGRA[21] = _IPP_CLIP_8U(y - yg[2]);
            pDstBGRA[22] = _IPP_CLIP_8U(y + yr[2]);
            //pDstBGRA[23]  = Alpha

		    /* Pixel 6 */
            y = pSrcMCUY[6];
            pDstBGRA[24] = _IPP_CLIP_8U(y + yb[3]);
            pDstBGRA[25] = _IPP_CLIP_8U(y - yg[3]);
            pDstBGRA[26] = _IPP_CLIP_8U(y + yr[3]);
            //pDstBGRA[27]  = Alpha

		    /* Pixel 7 */
            y = pSrcMCUY[7];
            pDstBGRA[28] = _IPP_CLIP_8U(y + yb[3]);
            pDstBGRA[29] = _IPP_CLIP_8U(y - yg[3]);
            pDstBGRA[30] = _IPP_CLIP_8U(y + yr[3]);
            //pDstBGRA[31]  = Alpha

		    /* Update the pointer to the output BGR data for the next row */
            pDstBGRA += dstStep;

		    /* Update the pointer to the input Y for the next row */
            pSrcMCUY      += 8;

        } /* for (j=8; j>0; j-=2) */

        if (3==i) {
            pDstBGRA-=32;
            pSrcMCUCb -= 4;
            pSrcMCUCr -= 4;
        } else {
            pDstBGRA-=(nOffset);
            pSrcMCUCb -= 28;
            pSrcMCUCr -= 28;
        }
    }

    return IPP_STATUS_OK;
}

/* EOF */
